<template>
  <div class="body">
    <header class="header">
      <div class="title">
        <img src="../../assets/images/01_11.png" alt="" class="img_zuo" @click="back" />
        <div>巡查列表</div>
        <img src="../../assets/images/dwxc/dwpc_06.gif" alt="" class="img_jia" @click="query">
      </div>
    </header>
    <div class="main top">
      <div class="tjb">
        <table class="t1">
          <thead class="table_hj">
            <tr>
              <td>巡查名称</td>
              <td>工作人员</td>
              <td>日期</td>
              <td>状态</td>
              <td>时间</td>
            </tr>
          </thead>
          <tbody class="tbody table1">
            <tr @click="Jump(item)" v-for="(item, index) in list" :key="index">
              <td>{{item.title}}</td>
              <td>
                {{qiegeren(item.worker)}}
              </td>
              <td>{{item.addtime}}</td>
              <td>{{item.status==0?"进行中":"已结束"}}</td>
              <td>
                <div class="shijian">
                  <span>{{item.begintime}}</span>
                  <span>{{item.endtime}}</span>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
    <queryPopup :delivertk_show="tk_show" @receivetkshow="handletkshow" @receiveparameter="handleparameter">
    </queryPopup>

  </div>
</template>

<script>
  import queryPopup from "./queryPop-up.vue"
  import qs from 'qs';
  export default {
    components: {
      queryPopup
    },
    name: 'dwxc_2_linelist',
    data() {
      return {
        tk_show: false,//是否显示弹框
        list: [],
      }
    },

    mounted() {
      var _this = this;

    },

    //进入该页面时，用之前保存的滚动位置赋值
    methods: {
      //  返回
      back() {
        this.$router.back()
      },
      query() {
        this.tk_show = true
      },
      handletkshow(bule) {//子组件返回的值是否显示弹框 
        this.tk_show = bule
      },
      handleparameter(obj) {
        console.log("接收的参数：", obj)
        var params = {
          userId: this.userid,
          mc: obj.name,
          zt: obj.state_text,
          beginDate: obj.start_time,
          endDate: obj.end_time,
          phone: localStorage.getItem("tel")
        }
        localStorage.setItem("dwxc_2_linelist_params", JSON.stringify(params))
        this.inof()
      },
      Jump(item) {//跳转

        if (document.documentElement && document.documentElement.scrollTop) {
          var t = document.documentElement.scrollTop;

        } else if (document.body) {
          var t = document.body.scrollTop;

        }
        sessionStorage.setItem("dwxc_2_scroll", t)
        var parent = {
          'name':item.title,
          path: "/dwxc_2_linelist"
        }
        if (item.status == 0) {
          localStorage.setItem("dwxc_5_back", JSON.stringify(parent))
          localStorage.setItem("dwxc_4_maplist_mapdataid", item.dataid)
          this.$router.push("/dwxc_5_inspectionpoint");

        } else {
          localStorage.setItem("dwxc_7_dataid", item.dataid)
          localStorage.setItem("dwxc_7_back", JSON.stringify(parent))
          this.$router.push("/dwxc_7_trajectories");
        }
      },
      inof() {//获取路线列表
        try {
          plus.nativeUI.showWaiting("正在加载...");
        } catch (e) {
          console.log("plus问题");
        }
        var params = JSON.parse(localStorage.getItem("dwxc_2_linelist_params"))
        this.axios
          .post(
            `${this.$global_msg.Url.host}/DotPlacePatrol/getSheQuMX`, qs.stringify(params)
          )
          .then((res) => {
            try {
              plus.nativeUI.closeWaiting();
            } catch (e) {
              console.log("plus问题");
            }
            console.log(res)
            if (res.data.code == 200) {
              if(res.data.rows.length>0){
                this.list = []
                this.list = res.data.rows
              }else{
                this.$toast("暂无数据");
              }
            } else {
              this.$toast(res.data.msg);
            }
          }).catch(err =>{
              this.$terminal._error(err)
          })
      },
      qiegeren(worker) {
        var workerSplit = worker.split(' ');
        workerSplit=new Set(workerSplit);
        workerSplit= [...workerSplit]
        console.log(workerSplit)
        if (workerSplit.length >= 2) {
          return workerSplit[0] + " " + workerSplit[1]
        }else{

          return workerSplit[0]
        }
      }
    },
    created() {
      // this.userid = localStorage.getItem("userId")
      // this.inof()
      // console.log(6 % 7)
    },
    beforeRouteEnter(to, from, next) {
      next((vm) => {
        vm.$nextTick(function () {
          console.log(to)
          console.log(from)
          if (from.path == "/dwxc_1_calendar") {
            vm.userid = localStorage.getItem("userId")
            vm.list = []
            vm.inof()
          } else {
            // $(".body").animate(
            //   { scrollTop: sessionStorage.getItem("dwxc_4_scroll") },
            //   0
            // );
            vm.inof()
            $(window).scrollTop(sessionStorage.getItem("dwxc_2_scroll"))
            // window.scrollTo(0,sessionStorage.getItem("dwxc_4_scroll"));
          }
        });

      });
    }
  }
</script>

<style scoped>
  /* 头部 */
  .header {
    height: 1.8519rem;
    background: #007aff;
    padding-top: 0.8333rem;
    box-sizing: border-box;
    width: 100%;
    z-index: 20;
    font-size: 0.388888rem;
    position: fixed;
    top: 0;
    left: 0;
  }

  .title {
    padding: 0 0.3704rem;
    display: flex;
    align-items: center;
    color: #fff;
  }

  .title>div {
    width: 100%;
    font-size: 0.4444rem;
    text-align: center;
  }

  .img_zuo {
    width: 0.2593rem;
    height: 0.463rem;
  }

  .img_jia {
    width: 0.4444rem;
    position: absolute;
    right: 0.3704rem;
  }

  /* 头部结束 */


  /*  */
  .top {
    margin-top: 1.8519rem;
  }

  .main {
    padding: 0.2778rem;
  }

  .tjb {
    background: #7ac0fe;
    border-radius: 0.2778rem;
  }

  .item {
    height: 1.2963rem;
    line-height: 1.2963rem;
    font-size: 0.481481rem;
    /* font-weight: 600; */
    text-align: center;
    /* border: 1px solid #A1A0A1; */
    border-bottom: none;
    color: #FFF;

  }


  .t1 {
    width: 100%;
    border-collapse: collapse;
  }

  .table_hj td {

    border: 1Px solid #fff;
    height: 1.3889rem;
    font-size: 0.3333rem;
    box-sizing: border-box;
    color: #fff;
    text-align: center;
    /* font-weight: 600; */
  }

  /* .table1 tr>td:nth-child(1) {
		width: 1.0185rem;
	} */

  .table1 tr>td:nth-child(1) {
    padding-left: 0.037rem;

  }

  .table1 tr>td:nth-child(2) {
    width: 2.2222rem;
    padding: 0 0.037rem;
  }

  .table1 tr>td:nth-child(3) {
    width: 2.037rem;
  }

  .table1 tr>td:nth-child(4) {
    width: 1.2037rem;
  }

  .table1 tr>td:nth-child(5) {
    width: 1.2037rem;
  }

  .table1 td {
    border: 1Px solid #fff;
    height: 1.2037rem;
    font-size: 0.3333rem;
    box-sizing: border-box;
    color: #fff;
    text-align: center;

  }

  .table1 tr>td:nth-child(1),
  .table1 tr>td:nth-child(2) {
    text-align: left;
  }


  .shijian {

    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }

  .shijian>span {
    font-size: 0.3333rem;
    height: 0.4259rem;
  }
</style>